

package com.maoshi.shop.coupon.multishop.controller;

import javax.validation.Valid;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.maoshi.shop.coupon.comment.model.CouponProd;
import com.maoshi.shop.coupon.comment.service.CouponProdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.maoshi.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 *
 * @author lgh on 2018/12/27.
 */
@RestController
@RequestMapping("/admin/couponProd")
public class CouponProdController {

    @Autowired
    private CouponProdService couponProdService;

	/**
	 * 分页获取
	 */
    @GetMapping("/page")
	public ResponseEntity<IPage<CouponProd>> page(CouponProd couponProd,PageParam<CouponProd> page){
		IPage<CouponProd> couponProds = couponProdService.page(page,new LambdaQueryWrapper<CouponProd>());
		return ResponseEntity.ok(couponProds);
	}

    /**
	 * 获取信息
	 */
	@GetMapping("/info/{id}")
	public ResponseEntity<CouponProd> info(@PathVariable("id") Long id){
		CouponProd couponProd = couponProdService.getById(id);
		return ResponseEntity.ok(couponProd);
	}

	/**
	 * 保存
	 */
	@PostMapping
	public ResponseEntity<Void> save(@RequestBody @Valid CouponProd couponProd){
		couponProdService.save(couponProd);
		return ResponseEntity.ok().build();
	}

	/**
	 * 修改
	 */
	@PutMapping
	public ResponseEntity<Void> update(@RequestBody @Valid CouponProd couponProd){
		couponProdService.updateById(couponProd);
		return ResponseEntity.ok().build();
	}

	/**
	 * 删除
	 */
	@DeleteMapping("/{id}")
	public ResponseEntity<Void> delete(@PathVariable Long id){
		couponProdService.removeById(id);
		return ResponseEntity.ok().build();
	}
}
